package homework2;

import java.util.HashSet;

//包含3个属性：name,age,salary。
public class Teacher implements Comparable<Teacher>{
	private String name;
	private int age;
	private double salary;
	private HashSet<Teacher> hashSet = new HashSet<Teacher>();
	
	public Teacher(String name, int age, double salary) {
		super();
		this.name = name;
		this.age = age;
		this.salary = salary;
	}
	public Teacher(){}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return this.age;
	}
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(null==obj) return false;
		if(this==obj) return true;
		if(obj instanceof Teacher){
			Teacher teacher = (Teacher)obj;
			return this.name.equals(teacher.name) && this.age==teacher.getAge();
		}
		return false;
	}
	@Override
	public int compareTo(Teacher o) {
		// TODO Auto-generated method stub
//		int num=0;
//		int len = this.name.length()>o.getName().length()?this.name.length():o.getName().length();
//		for(int i=0;i<len;i++){
//			if(this.name.charAt(i)==o.getName().charAt(i)){
//				continue;
//			}
//			num = this.name.charAt(i)>o.getName().charAt(i)?1:-1;
//			return num;
//		}
//		return 0;
		return this.name.compareTo(o.name);
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.name;
	}
	
}

